package com.example.SpringBoot_demo.util;

import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
 * 生成邮箱验证码
 *
 *
 * */
public class EmailCode {
    private static char mapTable[] = {
            '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', '0', '1',
            '2', '3', '4', '5', '6', '7',
            '8', '9','a','b','c','d','e',
            'f','g','h','i','g','k','l',
            'm','n','p','q','r','s','t',
            'u','v','w','x','y','z','0'};
    public static Map<String, Object> getImageCode() {
        Map<String,Object> returnMap = new HashMap<String, Object>();
        //生成随机类
        Random random = new Random();
        //取随机产生的码
        String strEnsure = "";
        //4代表4位验证码,如果要生成更多位的认证码,则加大数值
        for (int i = 0; i < 6; ++i) {
            strEnsure += mapTable[(int) (mapTable.length * Math.random())];
            //直接生成
            String str = strEnsure.substring(i, i + 1);
        }
        returnMap.put("strEnsure",strEnsure);
        return returnMap;
    }


}
